package org.jeecg.glr.service.impl;

import org.jeecg.glr.entity.GlrLightType;
import org.jeecg.glr.mapper.GlrLightTypeMapper;
import org.jeecg.glr.service.IGlrLightTypeService;
import org.jeecg.glr.util.StringUtil;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import javax.annotation.Resource;

/**
 * @Description: 路灯类型
 * @Author: jeecg-boot
 * @Date:   2020-03-05
 * @Version: V1.0
 */
@Service
public class GlrLightTypeServiceImpl extends ServiceImpl<GlrLightTypeMapper, GlrLightType> implements IGlrLightTypeService {

    @Resource GlrLightTypeMapper glrLightTypeMapper;

    @Override
    public GlrLightType getLightTypeByCode(String type) {
        GlrLightType lgType = new GlrLightType();
        lgType=glrLightTypeMapper.getLightTypeByCode(type);
        return lgType;
    }

    @Override
    public void saveLightType(GlrLightType glrLightType) {
        if(glrLightType.getId()==null){
            String orderCode=glrLightTypeMapper.getMaxLightTypeCode();
            if(StringUtil.isNotEmpty(orderCode)){
                int code=Integer.parseInt(orderCode)+1;
                orderCode= String.format("%02d", code);
            }else{
                orderCode="01";
            }
            glrLightType.setCode(orderCode);
        }
        super.save(glrLightType);
    }
}
